<?php
class Seo_AjaxController extends Zendvn_Controller_Action {
		
	protected $_arrParam; //Mang tham so nhan duoc khi mot Action chay
	protected $_currentController; //Duong dan cua Controller
	protected $_actionMain; //Duong dan cua Action chinh
	
	public function init(){
		
		$this->_arrParam = $this->_request->getParams(); //Mang tham so nhan duoc khi mot Action chay
		$this->_currentController = '/' . $this->_arrParam['module'] . '/' . $this->_arrParam['controller']; //Duong dan cua Controller
		$this->_actionMain = '/' . $this->_arrParam['module'] . '/'	. $this->_arrParam['controller'] . '/index'; //Duong dan cua Action chinh
	
		//Truyen ra ngoai view
		$this->view->arrParam = $this->_arrParam;
		$this->view->currentController = $this->_currentController;
		$this->view->actionMain = $this->_actionMain;
	
		$this->view->siteConfig = Zend_Registry::get('siteConfig');
		$template_path = TEMPLATE_PATH . "/admin/" . $this->view->siteConfig['template']['admin'];
		$this->loadTemplate($template_path, 'template.ini', 'daotao');
	}
	
	public function indexAction(){
		$this->_helper->layout->disableLayout();
		
		$tblFilter 		= new Seo_Model_Filter();
		$this->view->Items 	= $tblFilter->listItem($this->_arrParam, array('task'=>'admin-list'));
	}
	
	public function addAction(){
		$this->_helper->layout->disableLayout();
		
		$tblFilter = new Seo_Model_Filter();
		
		if($this->_request->isPost()){
			$validator = new Seo_Form_ValidateFilter($this->_arrParam);
			if($validator->isError() == true){
				$this->view->messageError = $validator->getMessageError();
				$this->view->Item = $validator->getData();
			}else{
				$arrParam = $validator->getData();
				$lastID = $tblFilter->saveItem($arrParam,array('task'=>'admin-add'));
			}
		}
	}
	
	public function editAction(){
		$this->_helper->layout->disableLayout();
		
		$tblFilter = new Seo_Model_Filter();
		$this->view->Item = $tblFilter->getItem($this->_arrParam,array('task'=>'admin-edit'));
		
		if($this->_request->isPost()){
				
			$validator = new Seo_Form_ValidateFilter($this->_arrParam);
			if($validator->isError() == true){
				$this->view->messageError = $validator->getMessageError();
				$this->view->Item = $validator->getData();
			}else{
				$arrParam = $validator->getData();
				$lastID = $tblFilter->saveItem($arrParam,array('task'=>'admin-edit'));
			}
		}
	}
	
	public function deleteAction(){
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		if($this->_request->isPost()){
			if(!empty($this->_arrParam['id'])){
				$tblFilter = new Seo_Model_Filter();
				$tblFilter->deleteItem($this->_arrParam, array('task'=>'admin-delete'));
			}
		}
	}
	
	public function statusAction(){
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		
		$tblFilter = new Seo_Model_Filter();
		$tblFilter->changeStatus($this->_arrParam);
	}
	
	public function thaytheAction(){
		$this->_helper->layout->disableLayout();
	}
	
}
